package cn.com.greatwall.system.modules.quartz.config;

import java.util.List;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import cn.com.greatwall.system.modules.quartz.domain.QuartzJob;
import cn.com.greatwall.system.modules.quartz.repository.QuartzJobRepository;
import cn.com.greatwall.system.modules.quartz.utils.QuartzManage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author herw
 * @Time 2020-11-05 13:45:57
 * @Version 1.0
 * @Description: TODO(用一句话描述该文件做什么)
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class JobRunner implements ApplicationRunner {
    private final QuartzJobRepository quartzJobRepository;
    private final QuartzManage quartzManage;
    
    /**
     * 项目启动时重新激活启用的定时任务
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("--------------------注入定时任务---------------------");
        List<QuartzJob> quartzJobs = quartzJobRepository.findByIsPauseIsFalse();
        quartzJobs.forEach(quartzManage::addJob);
        log.info("--------------------定时任务注入完成---------------------");
    }
}
